const { sqlite3 } = require('../../mysql')


// 获取网站设置数据
const webSetting = async (ctx) => {
  const data = await sqlite3('websetting').select()
  console.log(data)
  if (data) {
    ctx.body = {
      code: 200,
      item: data,
    }
  } else {
    ctx.body = {
      code: false
    }
  }
}

// 更新网站设置数据
const webSetUpdate = async (ctx) => {
  console.log('ctx:', ctx.request.body)
  let formData = ctx.request.body
  const data = await sqlite3('websetting').update(formData)
  if (data) {
    ctx.body = {
      code: 200,
      item: data,
    }
  } else {
    ctx.body = {
      code: false
    }
  }
}

// 获取网站管理用户数据
const getUser = async (ctx) => {
  console.log('ctx:', ctx.query)
  let username = ctx.query
  const data = await sqlite3('user').where(username).select()
  console.log(data)
  if (data) {
    ctx.body = {
      code: 200,
      item: data,
    }
  } else {
    ctx.body = {
      code: false
    }
  }
}

// 更新网站管理用户数据
const updateUser = async (ctx) => {
  console.log('ctx:', ctx.request.body)
  let formData = ctx.request.body
  const data = await sqlite3('websetting').update(formData)
  if (data) {
    ctx.body = {
      code: 200,
      item: data,
    }
  } else {
    ctx.body = {
      code: false
    }
  }
}


module.exports = { webSetting, webSetUpdate, getUser, updateUser }
